package com.zxm.ex.common.test;

public class T1 {

    private static int count=0;
    private static Object lock=new Object();
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {

                while (count < 100) {
                    synchronized (T1.class) {
                        if ((count & 1) == 1) {
                            System.out.println(Thread.currentThread().getName() + ":" + count++);
                        }
                    }
                }
            }
        }, "奇数").start();

        new Thread(new Runnable() {
            @Override
            public void run() {

                while (count < 100) {
                    synchronized (T1.class) {
                        if ((count & 1) == 0) {
                            System.out.println(Thread.currentThread().getName() + ":" + count++);
                        }
                    }
                }
            }
        }, "偶数").start();
    }
}
